/*
 * =====================================================================================
 *
 *       Filename:  testunit.c
 *
 *    Description:  
 *
 * =====================================================================================
 */
#include "common.h"

typedef struct TEST_ENTRY {
    char *fname;
    int needmongo;
    int needzmq;
    void (*test_func) (int, char **);
} _TestEntry;

void test_tick(int ,char **);

extern void test_send(int argc, char **argv);
extern void test_recv(int argc, char **argv);
extern void test_poll(int argc, char **argv);

void test_dzh2seq(int argc, char **argv)
{
    int i;

//uint64_t dzh2seq(char *name,uint32_t date)
    printf("%s start argv \n",__func__);
    dzh2seq(argv[3],atol(argv[4]));
    return;
}

void test_seq2date(int argc, char **argv)
{
    int i;

    printf("%s start argv \n",__func__);
    seq2date(atol(argv[3]));
    return;
}

void test_gennlist(int argc, char **argv)
{
    int i = 0;
    StockList *ylist;
    listIter *iter;
    listNode *node;
    StockBasic *sptr;
    printf("test start %s\n", __func__);
    ylist = dup_nlist_from(aFilter->glist, 0);

    list_each_from_head(ylist, iter, node) {
        sptr = node->value;
        printf("%s : %d %s\n", __func__, i++, sptr->sname);
    } list_each_end(iter);

    return;
}


_TestEntry TestEntry[] = {
    {"dzh2seq", 0,0, test_dzh2seq} ,
    {"seq2date", 0,0, test_seq2date} ,
    {"qsend", 0,0, test_send} ,
    {"qrecv", 0,0, test_recv} ,
    {"qpoll", 0,0, test_poll} ,
    {"gennlist", TRUE,0, test_gennlist} 
  };

void runtest(char *testname, int argc, char **argv)
{
    int i;
    for (i = 0; i < asizeof(TestEntry); i++) {
        if (strncmp(TestEntry[i].fname, testname, strlen(testname)) == 0) {

            if (TestEntry[i].needmongo == TRUE) {

                if (aFilter->mServer != NULL && aFilter->mstats != MONGO_OK) {
                    if ((aFilter->mstats = mongo_client(aFilter->mconn, aFilter->mServer, CONFIG_MONGO_PORT))
                         != MONGO_OK) {
                        printf("mongo connect failed\n");
                    } else
                        printf("mongo connected \n");
                }

            }


            if (TestEntry[i].needzmq== TRUE) {

                    ;;
            }

            TestEntry[i].test_func(argc, argv);

        }
    }

    return;
    //exit program now

}

